home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume24 / mkid2 / part01 next >
Encoding:
Internet Message Format  |  1991-10-09  |  48.5 KB

  1. Subject:  v24i089:  Program identifier database tools, Part01/07
  2. Newsgroups: comp.sources.unix
  3. Approved: rsalz@uunet.UU.NET
  4. X-Checksum-Snefru: 11ea33e4 f2785acc 972b9e4b af9f523a
  5.  
  6. Submitted-by: Tom Horsley <tom@hcx2.ssd.csd.harris.com>
  7. Posting-number: Volume 24, Issue 89
  8. Archive-name: mkid2/part01
  9.  
  10. [ The Subject line, my choice, is not very good.  MKID, however, is
  11.   a very good program.  -r$ ]
  12.  
  13.    An ID database is simply a file containing a list of file names, a
  14. list of identifiers, and a binary relation (stored as a bit matrix)
  15. indicating which of the identifiers appear in each file.  With this
  16. database and some tools to manipulate the data, a host of tasks
  17. become simpler and faster. You can `grep' through hundreds of files
  18. for a name, skipping the files that don't contain the name.  You can
  19. search for all the memos containing references to a project.  You can
  20. edit every file that calls some function, adding a new required
  21. argument. Anyone with a large software project to maintain, or a
  22. large set of text files to organize can benefit from the ID database
  23. and the tools that manipulate it.
  24.  
  25.    There are several programs in the ID family.  The `mkid' program
  26. scans the files, finds the identifiers and builds the ID database. 
  27. The `lid' and `aid' tools are used to generate lists of file names
  28. containing an identifier (perhaps to recompile every file that
  29. references a macro which just changed). The `eid' program will invoke
  30. an editor on each of the files containing an identifier and the `gid'
  31. program will `grep' for an identifier in the subset of files known to
  32. contain it.  The `pid' tool is used to query the path names of the
  33. files in the database (rather than the contents).  Finally, the `iid'
  34. tool is an interactive program supporting complex queries to
  35. intersect and join sets of file names.
  36.  
  37. #! /bin/sh
  38. # This is a shell archive.  Remove anything before this line, then unpack
  39. # it by saving it into a file and typing "sh file".  To overwrite existing
  40. # files, type "sh file -c".  You can also feed this as standard input via
  41. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  42. # will see the following message at the end:
  43. #        "End of archive 1 (of 7)."
  44. # Contents:  MANIFEST README Status TODO basename.c bitcount.c bitops.c
  45. #   bitops.h bitsvec.c bool.h bsearch.c bzero.c document.c extern.h
  46. #   fid.1 fid.c gets0.c getsFF.c gid.el hash.c id.h idx.c init.c
  47. #   kshgetwd.c numtst.c opensrc.c patchlevel.h radix.h stoi.c string.h
  48. #   tty.c uerror.c wmatch.c
  49. # Wrapped by tom@hcx2 on Tue Feb 26 10:03:00 1991
  50. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  51. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  52.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  53. else
  54. echo shar: Extracting \"'MANIFEST'\" \(1757 characters\)
  55. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  56. X   File Name        Archive #    Description
  57. X-----------------------------------------------------------
  58. X MANIFEST                   1    This shipping list
  59. X Makefile                   3    
  60. X README                     1    
  61. X Status                     1    
  62. X TODO                       1    
  63. X TUTORIAL                   4    
  64. X basename.c                 1    
  65. X bitcount.c                 1    
  66. X bitops.c                   1    
  67. X bitops.h                   1    
  68. X bitsvec.c                  1    
  69. X bool.h                     1    
  70. X bsearch.c                  1    
  71. X bzero.c                    1    
  72. X cannoname.c                2    
  73. X document.c                 1    
  74. X extern.h                   1    
  75. X fid.1                      1    
  76. X fid.c                      1    
  77. X gets0.c                    1    
  78. X getsFF.c                   1    
  79. X getscan.c                  3    
  80. X gid.el                     1    
  81. X hash.c                     1    
  82. X id.h                       1    
  83. X id.texinfo                 7    
  84. X idx.c                      1    
  85. X iid.1                      2    
  86. X iid.help                   2    
  87. X iid.y                      4    
  88. X iiddef.h                   3    
  89. X iidfun.c                   5    
  90. X init.c                     1    
  91. X kshgetwd.c                 1    
  92. X lid.1                      3    
  93. X lid.c                      6    
  94. X mkid.1                     2    
  95. X mkid.c                     5    
  96. X numtst.c                   1    
  97. X opensrc.c                  1    
  98. X patchlevel.h               1    
  99. X paths.c                    2    
  100. X radix.h                    1    
  101. X scan-asm.c                 3    
  102. X scan-c.c                   4    
  103. X scan-text.c                2    
  104. X stoi.c                     1    
  105. X string.h                   1    
  106. X symfunc.el                 2    
  107. X tty.c                      1    
  108. X uerror.c                   1    
  109. X unsymlink.c                2    
  110. X wmatch.c                   1    
  111. END_OF_FILE
  112. if test 1757 -ne `wc -c <'MANIFEST'`; then
  113.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  114. fi
  115. # end of 'MANIFEST'
  116. fi
  117. if test -f 'README' -a "${1}" != "-c" ; then 
  118.   echo shar: Will not clobber existing file \"'README'\"
  119. else
  120. echo shar: Extracting \"'README'\" \(2051 characters\)
  121. sed "s/^X//" >'README' <<'END_OF_FILE'
  122. XHere is the overview section of the id.texinfo document:
  123. X
  124. XOverview
  125. X********
  126. X
  127. X   An ID database is simply a file containing a list of file names, a
  128. Xlist of identifiers, and a binary relation (stored as a bit matrix)
  129. Xindicating which of the identifiers appear in each file.  With this
  130. Xdatabase and some tools to manipulate the data, a host of tasks
  131. Xbecome simpler and faster. You can `grep' through hundreds of files
  132. Xfor a name, skipping the files that don't contain the name.  You can
  133. Xsearch for all the memos containing references to a project.  You can
  134. Xedit every file that calls some function, adding a new required
  135. Xargument. Anyone with a large software project to maintain, or a
  136. Xlarge set of text files to organize can benefit from the ID database
  137. Xand the tools that manipulate it.
  138. X
  139. X   There are several programs in the ID family.  The `mkid' program
  140. Xscans the files, finds the identifiers and builds the ID database. 
  141. XThe `lid' and `aid' tools are used to generate lists of file names
  142. Xcontaining an identifier (perhaps to recompile every file that
  143. Xreferences a macro which just changed). The `eid' program will invoke
  144. Xan editor on each of the files containing an identifier and the `gid'
  145. Xprogram will `grep' for an identifier in the subset of files known to
  146. Xcontain it.  The `pid' tool is used to query the path names of the
  147. Xfiles in the database (rather than the contents).  Finally, the `iid'
  148. Xtool is an interactive program supporting complex queries to
  149. Xintersect and join sets of file names.
  150. X
  151. XThat ends the overview.
  152. X
  153. X
  154. XTo build and install mkid, look through the Makefile - all the various
  155. Xconfiguration options are (more or less :-) documented there. Change them
  156. Xaround to work for your system, and type "make" to build the programs.
  157. X
  158. XTo make the texinfo online documentation type "make id-info".
  159. X
  160. XTo make the printed manual construct the .dvi file with "make id.dvi".  You
  161. Xwill have to figure out how printing .dvi files works on your system (talk
  162. Xto a local TeX guru -- if you don't have TeX, you won't be able to print the
  163. Xmanual, sorry).
  164. END_OF_FILE
  165. if test 2051 -ne `wc -c <'README'`; then
  166.     echo shar: \"'README'\" unpacked with wrong size!
  167. fi
  168. # end of 'README'
  169. fi
  170. if test -f 'Status' -a "${1}" != "-c" ; then 
  171.   echo shar: Will not clobber existing file \"'Status'\"
  172. else
  173. echo shar: Extracting \"'Status'\" \(1537 characters\)
  174. sed "s/^X//" >'Status' <<'END_OF_FILE'
  175. XIn the original alt.sources posting, this file started off:
  176. X
  177. X   This is the mkid package originally posted to the net around September of
  178. X   1987 by Greg McGary (who then vanished from the net). Since then I have been
  179. X   extensively hacking it, and so have others. In an effort to have all of us
  180. X   benefit from the modifications and improvements we all have made, I have
  181. X   (probably foolishly :-) volunteered to "take over" mkid.
  182. X
  183. XSince then, Greg has revealed that he is still alive and on the net, and
  184. Xhe apparently has lots of plans for mkid revisions (but not much time to
  185. Xdo them -- a situation we are probably all familiar with).
  186. X
  187. XAnyway, after I post this version to comp.sources.unix, I will probably
  188. Xlet Greg take over as the official maintainer.
  189. X
  190. XThis version contains some cleanup work done since the alt.sources posting
  191. X(but no major changes). It also comes with a brand new id.texinfo file
  192. Xcontaining the latest and greatest documentation for the tools (Note: I have
  193. Xno plans to upgrade the man pages, the texinfo doc is the only place where
  194. Xthe latest and greatest options are documented right now).
  195. X
  196. XThis is the final posting to alt.sources. It contains the patches to upgrade
  197. Xthe original alt.sources posting to what I now have. If a few days go past
  198. Xwith no additional bugs cropping up, I will send it all off to
  199. Xcomp.sources.unix.
  200. X
  201. XYou can reach me (Tom Horsley) at:
  202. X   tahorsley@csd.harris.com or ...!uunet!hcx1!tahorsley
  203. X
  204. XThe email address I have for Greg McGary is:
  205. X   gm@blip.wsrcc.com or ...!uunet!wsrcc!blip!gm
  206. END_OF_FILE
  207. if test 1537 -ne `wc -c <'Status'`; then
  208.     echo shar: \"'Status'\" unpacked with wrong size!
  209. fi
  210. # end of 'Status'
  211. fi
  212. if test -f 'TODO' -a "${1}" != "-c" ; then 
  213.   echo shar: Will not clobber existing file \"'TODO'\"
  214. else
  215. echo shar: Extracting \"'TODO'\" \(546 characters\)
  216. sed "s/^X//" >'TODO' <<'END_OF_FILE'
  217. XEnhancements:
  218. X~~~~~~~~~~~~~
  219. Xmkid:
  220. X    handle attributes: IDN_NOISE
  221. X    add makefile scanner
  222. X
  223. Xgetid-c:
  224. X    add stuff to recognize float & double constants properly.
  225. X
  226. X[lgea]id:
  227. X    recursively search sub-dirs for ID databases and optionally
  228. X        merge everything into one BIG list
  229. Xlid:
  230. X    print attribute flags, add cmd-line args to query by flags
  231. X    break out searching junk into lib-funcs that are useful to editors
  232. X
  233. XNew Applications:
  234. X~~~~~~~~~~~~~~~~~
  235. Xignid:
  236. X    frob the IDN_NOISE attribute of an id in an existing ID database.
  237. X        takes ids on command line or stdin.
  238. END_OF_FILE
  239. if test 546 -ne `wc -c <'TODO'`; then
  240.     echo shar: \"'TODO'\" unpacked with wrong size!
  241. fi
  242. # end of 'TODO'
  243. fi
  244. if test -f 'basename.c' -a "${1}" != "-c" ; then 
  245.   echo shar: Will not clobber existing file \"'basename.c'\"
  246. else
  247. echo shar: Extracting \"'basename.c'\" \(433 characters\)
  248. sed "s/^X//" >'basename.c' <<'END_OF_FILE'
  249. X/* Copyright (c) 1986, Greg McGary */
  250. Xstatic char sccsid[] = "@(#)basename.c    1.1 86/10/09";
  251. X
  252. X#include    <string.h>
  253. X
  254. Xchar *basename();
  255. Xchar *dirname();
  256. X
  257. Xchar *
  258. Xbasename(path)
  259. X    char        *path;
  260. X{
  261. X    char        *base;
  262. X
  263. X    if ((base = strrchr(path, '/')) == 0)
  264. X        return path;
  265. X    else
  266. X        return ++base;
  267. X}
  268. X
  269. Xchar *
  270. Xdirname(path)
  271. X    char        *path;
  272. X{
  273. X    char        *base;
  274. X
  275. X    if ((base = strrchr(path, '/')) == 0)
  276. X        return ".";
  277. X    else
  278. X        return strnsav(path, base - path);
  279. X}
  280. END_OF_FILE
  281. if test 433 -ne `wc -c <'basename.c'`; then
  282.     echo shar: \"'basename.c'\" unpacked with wrong size!
  283. fi
  284. # end of 'basename.c'
  285. fi
  286. if test -f 'bitcount.c' -a "${1}" != "-c" ; then 
  287.   echo shar: Will not clobber existing file \"'bitcount.c'\"
  288. else
  289. echo shar: Extracting \"'bitcount.c'\" \(643 characters\)
  290. sed "s/^X//" >'bitcount.c' <<'END_OF_FILE'
  291. X/* Copyright (c) 1986, Greg McGary */
  292. Xstatic char sccsid[] = "@(#)bitcount.c    1.1 86/10/09";
  293. X
  294. Xint bitCount();
  295. Xint bitsCount();
  296. X
  297. X/*
  298. X    Count the number of 1 bits in the given integer.
  299. X*/
  300. Xstatic char bitcnt[] = {
  301. X/*    0 1 2 3 4 5 6 7    8 9 a b c d e f    */
  302. X    0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4
  303. X};
  304. Xint
  305. XbitCount(mask)
  306. X    register unsigned    mask;
  307. X{
  308. X    register int    nybbles = 8;
  309. X    register int    cnt = 0;
  310. X
  311. X    while (mask && nybbles--) {
  312. X        cnt += bitcnt[mask&0xf];
  313. X        mask >>= 4;
  314. X    }
  315. X    return cnt;
  316. X}
  317. X
  318. Xint
  319. XbitsCount(bitv, n)
  320. X    register char    *bitv;
  321. X    register int    n;
  322. X{
  323. X    register int    count = 0;
  324. X
  325. X    while (n--) {
  326. X        count += bitcnt[*bitv&0xf] + bitcnt[(*bitv>>4)&0xf];
  327. X        bitv++;
  328. X    }
  329. X}
  330. END_OF_FILE
  331. if test 643 -ne `wc -c <'bitcount.c'`; then
  332.     echo shar: \"'bitcount.c'\" unpacked with wrong size!
  333. fi
  334. # end of 'bitcount.c'
  335. fi
  336. if test -f 'bitops.c' -a "${1}" != "-c" ; then 
  337.   echo shar: Will not clobber existing file \"'bitops.c'\"
  338. else
  339. echo shar: Extracting \"'bitops.c'\" \(992 characters\)
  340. sed "s/^X//" >'bitops.c' <<'END_OF_FILE'
  341. X/* Copyright (c) 1986, Greg McGary */
  342. Xstatic char sccsid[] = "@(#)bitops.c    1.1 86/10/09";
  343. X
  344. X#include    <bitops.h>
  345. X
  346. Xchar *bitsset();
  347. Xchar *bitsclr();
  348. Xchar *bitsand();
  349. Xchar *bitsxor();
  350. Xint bitstst();
  351. Xint bitsany();
  352. X
  353. Xchar *
  354. Xbitsset(s1, s2, n)
  355. X    register char    *s1;
  356. X    register char    *s2;
  357. X    register int    n;
  358. X{
  359. X    while (n--)
  360. X        *s1++ |= *s2++;
  361. X
  362. X    return s1;
  363. X}
  364. X
  365. Xchar *
  366. Xbitsclr(s1, s2, n)
  367. X    register char    *s1;
  368. X    register char    *s2;
  369. X    register int    n;
  370. X{
  371. X    while (n--)
  372. X        *s1++ &= ~*s2++;
  373. X
  374. X    return s1;
  375. X}
  376. X
  377. Xchar *
  378. Xbitsand(s1, s2, n)
  379. X    register char    *s1;
  380. X    register char    *s2;
  381. X    register int    n;
  382. X{
  383. X    while (n--)
  384. X        *s1++ &= *s2++;
  385. X
  386. X    return s1;
  387. X}
  388. X
  389. Xchar *
  390. Xbitsxor(s1, s2, n)
  391. X    register char    *s1;
  392. X    register char    *s2;
  393. X    register int    n;
  394. X{
  395. X    while (n--)
  396. X        *s1++ ^= *s2++;
  397. X
  398. X    return s1;
  399. X}
  400. X
  401. Xint
  402. Xbitstst(s1, s2, n)
  403. X    register char    *s1;
  404. X    register char    *s2;
  405. X    register int    n;
  406. X{
  407. X    while (n--)
  408. X        if (*s1++ & *s2++)
  409. X            return 1;
  410. X
  411. X    return 0;
  412. X}
  413. X
  414. Xint
  415. Xbitsany(s, n)
  416. X    register char    *s;
  417. X    register int    n;
  418. X{
  419. X    while (n--)
  420. X        if (*s++)
  421. X            return 1;
  422. X
  423. X    return 0;
  424. X}
  425. END_OF_FILE
  426. if test 992 -ne `wc -c <'bitops.c'`; then
  427.     echo shar: \"'bitops.c'\" unpacked with wrong size!
  428. fi
  429. # end of 'bitops.c'
  430. fi
  431. if test -f 'bitops.h' -a "${1}" != "-c" ; then 
  432.   echo shar: Will not clobber existing file \"'bitops.h'\"
  433. else
  434. echo shar: Extracting \"'bitops.h'\" \(537 characters\)
  435. sed "s/^X//" >'bitops.h' <<'END_OF_FILE'
  436. X/* Copyright (c) 1986, Greg McGary */
  437. X/* @(#)bitops.h    1.1 86/10/09 */
  438. X
  439. X#define    BITTST(ba, bn)    ((ba)[(bn) >> 3] &  (1 << ((bn) & 0x07)))
  440. X#define    BITSET(ba, bn)    ((ba)[(bn) >> 3] |= (1 << ((bn) & 0x07)))
  441. X#define    BITCLR(ba, bn)    ((ba)[(bn) >> 3] &=~(1 << ((bn) & 0x07)))
  442. X#define    BITAND(ba, bn)    ((ba)[(bn) >> 3] &= (1 << ((bn) & 0x07)))
  443. X#define    BITXOR(ba, bn)    ((ba)[(bn) >> 3] ^= (1 << ((bn) & 0x07)))
  444. X
  445. Xextern char *bitsand();
  446. Xextern char *bitsclr();
  447. Xextern char *bitsset();
  448. Xextern char *bitsxor();
  449. Xextern int bitsany();
  450. Xextern int bitstst();
  451. END_OF_FILE
  452. if test 537 -ne `wc -c <'bitops.h'`; then
  453.     echo shar: \"'bitops.h'\" unpacked with wrong size!
  454. fi
  455. # end of 'bitops.h'
  456. fi
  457. if test -f 'bitsvec.c' -a "${1}" != "-c" ; then 
  458.   echo shar: Will not clobber existing file \"'bitsvec.c'\"
  459. else
  460. echo shar: Extracting \"'bitsvec.c'\" \(1614 characters\)
  461. sed "s/^X//" >'bitsvec.c' <<'END_OF_FILE'
  462. X/* Copyright (c) 1986, Greg McGary */
  463. Xstatic char sccsid[] = "@(#)bitsvec.c    1.1 86/10/09";
  464. X
  465. X#include    <stdio.h>
  466. X#include    <bitops.h>
  467. X#include    <string.h>
  468. X#include    <extern.h>
  469. X#include    <id.h>
  470. X
  471. Xint vecToBits();
  472. Xint bitsToVec();
  473. Xchar *intToStr();
  474. Xint getsFF();
  475. Xint strToInt();
  476. Xvoid skipFF();
  477. X
  478. Xint
  479. XvecToBits(bitArray, vec, size)
  480. X    register char    *bitArray;
  481. X    register char    *vec;
  482. X    int        size;
  483. X{
  484. X    register int    i;
  485. X    int        count;
  486. X
  487. X    for (count = 0; (*vec & 0xff) != 0xff; count++) {
  488. X        i = strToInt(vec, size);
  489. X        BITSET(bitArray, i);
  490. X        vec += size;
  491. X    }
  492. X    return count;
  493. X}
  494. X
  495. Xint
  496. XbitsToVec(vec, bitArray, bitCount, size)
  497. X    register char    *vec;
  498. X    char        *bitArray;
  499. X    int        bitCount;
  500. X    int        size;
  501. X{
  502. X    register char    *element;
  503. X    register int    i;
  504. X    int        count;
  505. X
  506. X    for (count = i = 0; i < bitCount; i++) {
  507. X        if (!BITTST(bitArray, i))
  508. X            continue;
  509. X        element = intToStr(i, size);
  510. X        switch (size) {
  511. X        case 4: *vec++ = *element++;
  512. X        case 3: *vec++ = *element++;
  513. X        case 2: *vec++ = *element++;
  514. X        case 1: *vec++ = *element++;
  515. X        }
  516. X        count++;
  517. X    }
  518. X    *vec++ = 0xff;
  519. X
  520. X    return count;
  521. X}
  522. X
  523. Xchar *
  524. XintToStr(i, size)
  525. X    register int    i;
  526. X    int        size;
  527. X{
  528. X    static char    buf0[4];
  529. X    register char    *bufp = &buf0[size];
  530. X
  531. X    switch (size)
  532. X    {
  533. X    case 4:    *--bufp = (i & 0xff); i >>= 8;
  534. X    case 3: *--bufp = (i & 0xff); i >>= 8;
  535. X    case 2: *--bufp = (i & 0xff); i >>= 8;
  536. X    case 1: *--bufp = (i & 0xff);
  537. X    }
  538. X    return buf0;
  539. X}
  540. X
  541. Xint
  542. XstrToInt(bufp, size)
  543. X    register char    *bufp;
  544. X    int        size;
  545. X{
  546. X    register int    i = 0;
  547. X
  548. X    bufp--;
  549. X    switch (size)
  550. X    {
  551. X    case 4: i |= (*++bufp & 0xff); i <<= 8;
  552. X    case 3: i |= (*++bufp & 0xff); i <<= 8;
  553. X    case 2: i |= (*++bufp & 0xff); i <<= 8;
  554. X    case 1: i |= (*++bufp & 0xff);
  555. X    }
  556. X    return i;
  557. X}
  558. END_OF_FILE
  559. if test 1614 -ne `wc -c <'bitsvec.c'`; then
  560.     echo shar: \"'bitsvec.c'\" unpacked with wrong size!
  561. fi
  562. # end of 'bitsvec.c'
  563. fi
  564. if test -f 'bool.h' -a "${1}" != "-c" ; then 
  565.   echo shar: Will not clobber existing file \"'bool.h'\"
  566. else
  567. echo shar: Extracting \"'bool.h'\" \(128 characters\)
  568. sed "s/^X//" >'bool.h' <<'END_OF_FILE'
  569. X/* Copyright (c) 1986, Greg McGary */
  570. X/* @(#)bool.h    1.1 86/10/09 */
  571. X
  572. Xtypedef    int    bool;
  573. X#define    TRUE    (0==0)
  574. X#define    FALSE    (0!=0)
  575. END_OF_FILE
  576. if test 128 -ne `wc -c <'bool.h'`; then
  577.     echo shar: \"'bool.h'\" unpacked with wrong size!
  578. fi
  579. # end of 'bool.h'
  580. fi
  581. if test -f 'bsearch.c' -a "${1}" != "-c" ; then 
  582.   echo shar: Will not clobber existing file \"'bsearch.c'\"
  583. else
  584. echo shar: Extracting \"'bsearch.c'\" \(692 characters\)
  585. sed "s/^X//" >'bsearch.c' <<'END_OF_FILE'
  586. X/* Copyright (c) 1986, Greg McGary */
  587. Xstatic char sccsid[] = "@(#)bsearch.c    1.1 86/10/09";
  588. X
  589. Xchar *bsearch();
  590. X
  591. X/*
  592. X    Binary search -- from Knuth (6.2.1) Algorithm B
  593. X*/
  594. Xchar *
  595. Xbsearch(key, base, nel, width, compar)
  596. X    char        *key;
  597. X    register char    *base;
  598. X    unsigned int    nel;
  599. X    int        width;
  600. X    int        (*compar)();
  601. X{
  602. X    register char    *last;
  603. X    register char    *position;
  604. X    register int    result;
  605. X    int        width2;
  606. X
  607. X    width2 = width * 2;
  608. X    last = &base[width * (nel - 1)];
  609. X
  610. X    while (last >= base) {
  611. X        position = &base[width * ((last - base)/width2)];
  612. X        
  613. X        if ((result = (*compar)(key, position)) == 0)
  614. X            return position;
  615. X        if (result < 0)
  616. X            last = position - width;
  617. X        else
  618. X            base = position + width;
  619. X    }
  620. X    return (char *)0;
  621. X}
  622. END_OF_FILE
  623. if test 692 -ne `wc -c <'bsearch.c'`; then
  624.     echo shar: \"'bsearch.c'\" unpacked with wrong size!
  625. fi
  626. # end of 'bsearch.c'
  627. fi
  628. if test -f 'bzero.c' -a "${1}" != "-c" ; then 
  629.   echo shar: Will not clobber existing file \"'bzero.c'\"
  630. else
  631. echo shar: Extracting \"'bzero.c'\" \(199 characters\)
  632. sed "s/^X//" >'bzero.c' <<'END_OF_FILE'
  633. X/* Copyright (c) 1986, Greg McGary */
  634. Xstatic char sccsid[] = "@(#)bzero.c    1.1 86/10/09";
  635. X
  636. Xvoid bzero();
  637. X
  638. Xvoid
  639. Xbzero(s, n)
  640. X    register char    *s;
  641. X    register int    n;
  642. X{
  643. X    if (n) do
  644. X        *s++ = 0;
  645. X    while (--n);
  646. X}
  647. END_OF_FILE
  648. if test 199 -ne `wc -c <'bzero.c'`; then
  649.     echo shar: \"'bzero.c'\" unpacked with wrong size!
  650. fi
  651. # end of 'bzero.c'
  652. fi
  653. if test -f 'document.c' -a "${1}" != "-c" ; then 
  654.   echo shar: Will not clobber existing file \"'document.c'\"
  655. else
  656. echo shar: Extracting \"'document.c'\" \(188 characters\)
  657. sed "s/^X//" >'document.c' <<'END_OF_FILE'
  658. X/* Copyright (c) 1986, Greg McGary */
  659. Xstatic char sccsid[] = "@(#)document.c    1.1 86/10/09";
  660. X
  661. Xvoid document();
  662. X
  663. Xvoid
  664. Xdocument(doc)
  665. X    char        **doc;
  666. X{
  667. X    while (*doc)
  668. X        printf("%s\n", *doc++);
  669. X}
  670. END_OF_FILE
  671. if test 188 -ne `wc -c <'document.c'`; then
  672.     echo shar: \"'document.c'\" unpacked with wrong size!
  673. fi
  674. # end of 'document.c'
  675. fi
  676. if test -f 'extern.h' -a "${1}" != "-c" ; then 
  677.   echo shar: Will not clobber existing file \"'extern.h'\"
  678. else
  679. echo shar: Extracting \"'extern.h'\" \(1386 characters\)
  680. sed "s/^X//" >'extern.h' <<'END_OF_FILE'
  681. X/* Copyright (c) 1986, Greg McGary */
  682. X/* @(#)extern.h    1.1 86/10/09 */
  683. X
  684. X/* miscellaneous external declarations */
  685. X
  686. Xextern FILE *initID();
  687. Xextern char *getFilter();
  688. Xextern FILE *openSrcFILE();
  689. Xextern void closeSrcFILE();
  690. Xextern char *(*getScanner())();
  691. Xextern char *basename();
  692. Xextern char *bsearch();
  693. Xextern char *calloc();
  694. Xextern char *coRCS();
  695. Xextern char *dirname();
  696. Xextern char *getAsmId();
  697. Xextern char *getCId();
  698. Xextern char *getLanguage();
  699. Xextern char *getTextId();
  700. Xextern char *getSCCS();
  701. Xextern char *getVhilId();
  702. Xextern char *getenv();
  703. Xextern char *hashSearch();
  704. Xextern char *intToStr();
  705. Xextern char *malloc();
  706. Xextern char *regcmp();
  707. Xextern char *regex();
  708. Xextern char *rootName();
  709. Xextern char *spanPath();
  710. Xextern char *relPath();
  711. Xextern char *LookUp();
  712. Xextern char *suffName();
  713. Xextern char *uerror();
  714. Xextern int bitCount();
  715. Xextern int bitsCount();
  716. Xextern int bitsToVec();
  717. Xextern int canCrunch();
  718. Xextern int dtoi();
  719. Xextern int fgets0();
  720. Xextern int getsFF();
  721. Xextern int h1str();
  722. Xextern int h2str();
  723. Xextern int strToInt();
  724. Xextern int otoi();
  725. Xextern int radix();
  726. Xextern int stoi();
  727. Xextern int vecToBits();
  728. Xextern int wordMatch();
  729. Xextern int xtoi();
  730. Xextern void bzero();
  731. Xextern void document();
  732. Xextern void filerr();
  733. Xextern void setAsmArgs();
  734. Xextern void setCArgs();
  735. Xextern void setScanArgs();
  736. Xextern void setTextArgs();
  737. Xextern void skipFF();
  738. X
  739. Xextern char *MyName;
  740. Xextern int errno;
  741. END_OF_FILE
  742. if test 1386 -ne `wc -c <'extern.h'`; then
  743.     echo shar: \"'extern.h'\" unpacked with wrong size!
  744. fi
  745. # end of 'extern.h'
  746. fi
  747. if test -f 'fid.1' -a "${1}" != "-c" ; then 
  748.   echo shar: Will not clobber existing file \"'fid.1'\"
  749. else
  750. echo shar: Extracting \"'fid.1'\" \(576 characters\)
  751. sed "s/^X//" >'fid.1' <<'END_OF_FILE'
  752. X.TH FID 1
  753. X.SH NAME
  754. Xfid \- query id database for specific files
  755. X.SH SYNOPSIS
  756. X.B fid
  757. X.RB [ \-f \^file]
  758. Xfile1 [ file2 ]
  759. X.SH DESCRIPTION
  760. X.I Fid
  761. Xis a query tool for the id database. If you specify a single file
  762. Xname as an argument, it prints a list of all the identifiers that
  763. Xoccur in that file.
  764. X.PP
  765. XWhen you give it two file names it takes the intersection. It prints
  766. Xonly the list of identifiers that occur in both files.
  767. X.PP
  768. XThe following options are recognized:
  769. X.TP 10
  770. X.BR \-f file\^
  771. XUse
  772. X.I file\^
  773. Xas the database instead of the default
  774. X.BR ID .
  775. X.SH SEE ALSO
  776. Xmkid(1),
  777. Xlid(1).
  778. END_OF_FILE
  779. if test 576 -ne `wc -c <'fid.1'`; then
  780.     echo shar: \"'fid.1'\" unpacked with wrong size!
  781. fi
  782. # end of 'fid.1'
  783. fi
  784. if test -f 'fid.c' -a "${1}" != "-c" ; then 
  785.   echo shar: Will not clobber existing file \"'fid.c'\"
  786. else
  787. echo shar: Extracting \"'fid.c'\" \(2394 characters\)
  788. sed "s/^X//" >'fid.c' <<'END_OF_FILE'
  789. Xstatic char copyright[] = "@(#)Copyright (c) 1986, Greg McGary";
  790. Xstatic char sccsid[] = "@(#)fid.c    1.2 86/10/17";
  791. X
  792. X#include    <bool.h>
  793. X#include    <stdio.h>
  794. X#include    <string.h>
  795. X#include    <ctype.h>
  796. X#include    <radix.h>
  797. X#include    <id.h>
  798. X#include    <bitops.h>
  799. X#include    <extern.h>
  800. X
  801. Xvoid fileId();
  802. X
  803. XFILE        *IdFILE;
  804. Xstruct idhead    Idh;
  805. Xstruct idarg    *IdArgs;
  806. X
  807. Xchar *MyName;
  808. Xstatic void
  809. Xusage()
  810. X{
  811. X    fprintf(stderr, "Usage: %s [-f<file>] file1 file2\n", MyName);
  812. X    exit(1);
  813. X}
  814. Xmain(argc, argv)
  815. X    int        argc;
  816. X    char        **argv;
  817. X{
  818. X    char        *idFile = IDFILE;
  819. X    char        *arg;
  820. X    float        occurPercent = 0.0;
  821. X    int        occurNumber = 0;
  822. X    int        op;
  823. X
  824. X    MyName = basename(GETARG(argc, argv));
  825. X
  826. X    while (argc) {
  827. X        arg = GETARG(argc, argv);
  828. X        switch (op = *arg++)
  829. X        {
  830. X        case '-':
  831. X        case '+':
  832. X            break;
  833. X        default:
  834. X            UNGETARG(argc, argv);
  835. X            goto argsdone;
  836. X        }
  837. X        while (*arg) switch (*arg++)
  838. X        {
  839. X        case 'f': idFile = arg; goto nextarg;
  840. X        default: usage();
  841. X        }
  842. X    nextarg:;
  843. X    }
  844. Xargsdone:
  845. X
  846. X    if ((idFile = LookUp(idFile)) == NULL) {
  847. X        filerr("open", idFile);
  848. X        exit(1);
  849. X    }
  850. X    if ((IdFILE = initID(idFile, &Idh, &IdArgs)) == NULL) {
  851. X        filerr("open", idFile);
  852. X        exit(1);
  853. X    }
  854. X
  855. X    if (argc < 1 || argc > 2)
  856. X        usage();
  857. X
  858. X    fileId(argc, argv);
  859. X    exit(0);
  860. X}
  861. X
  862. Xvoid
  863. XfileId(argc, argv)
  864. X    int        argc;
  865. X    char        **argv;
  866. X{
  867. X    char        *buf;
  868. X    int        want, got;
  869. X    int        bitoff[2];
  870. X    int        i, j;
  871. X    int        argLength;
  872. X    int        pathLength;
  873. X    int        lengthDiff;
  874. X    char        *pathVec;
  875. X    register struct idarg    *idArgs;
  876. X
  877. X    want = 0;
  878. X    for (j = 0; j < argc; j++, argv++) {
  879. X        want |= (1<<j);
  880. X        argLength = strlen(*argv);
  881. X        bitoff[j] = -1;
  882. X        for (idArgs = IdArgs, i = 0; i < Idh.idh_pthc; i++, idArgs++) {
  883. X            pathLength = strlen(idArgs->ida_arg);
  884. X            if (argLength > pathLength)
  885. X                continue;
  886. X            lengthDiff = pathLength - argLength;
  887. X            if (strequ(&idArgs->ida_arg[lengthDiff], *argv)) {
  888. X                bitoff[j] = i;
  889. X                break;
  890. X            }
  891. X        }
  892. X        if (bitoff[j] < 0) {
  893. X            fprintf(stderr, "%s: not found\n", *argv);
  894. X            exit(1);
  895. X        }
  896. X    }
  897. X
  898. X    buf = malloc((int)Idh.idh_bsiz);
  899. X    fseek(IdFILE, Idh.idh_namo, 0);
  900. X
  901. X    for (i = 0; i < Idh.idh_namc; i++) {
  902. X        pathVec = 1 + buf + fgets0(buf, Idh.idh_bsiz, IdFILE);
  903. X        getsFF(pathVec, IdFILE);
  904. X        got = 0;
  905. X        while ((*pathVec & 0xff) != 0xff) {
  906. X            j = strToInt(pathVec, Idh.idh_vecc);
  907. X            if ((want & (1<<0)) && j == bitoff[0])
  908. X                got |= (1<<0);
  909. X            if ((want & (1<<1)) && j == bitoff[1])
  910. X                got |= (1<<1);
  911. X            if (got == want) {
  912. X                printf("%s\n", ID_STRING(buf));
  913. X                break;
  914. X            }
  915. X            pathVec += Idh.idh_vecc;
  916. X        }
  917. X    }
  918. X}
  919. END_OF_FILE
  920. if test 2394 -ne `wc -c <'fid.c'`; then
  921.     echo shar: \"'fid.c'\" unpacked with wrong size!
  922. fi
  923. # end of 'fid.c'
  924. fi
  925. if test -f 'gets0.c' -a "${1}" != "-c" ; then 
  926.   echo shar: Will not clobber existing file \"'gets0.c'\"
  927. else
  928. echo shar: Extracting \"'gets0.c'\" \(575 characters\)
  929. sed "s/^X//" >'gets0.c' <<'END_OF_FILE'
  930. X/* Copyright (c) 1986, Greg McGary */
  931. Xstatic char sccsid[] = "@(#)gets0.c    1.1 86/10/09";
  932. X
  933. X#include    <stdio.h>
  934. X
  935. Xint fgets0();
  936. X
  937. X/*
  938. X    This is like fgets(3s), except that lines are
  939. X    delimited by NULs rather than newlines.  Also,
  940. X    we return the number of characters gotten rather
  941. X    than the address of buf0.
  942. X*/
  943. Xint
  944. Xfgets0(buf0, size, inFILE)
  945. X    char        *buf0;
  946. X    int        size;
  947. X    register FILE    *inFILE;
  948. X{
  949. X    register char    *buf;
  950. X    register int    c;
  951. X    register char    *end;
  952. X
  953. X    buf = buf0;
  954. X    end = &buf[size];
  955. X    while ((c = getc(inFILE)) > 0 && buf < end)
  956. X        *buf++ = c;
  957. X    *buf = '\0';
  958. X    return (buf - buf0);
  959. X}
  960. END_OF_FILE
  961. if test 575 -ne `wc -c <'gets0.c'`; then
  962.     echo shar: \"'gets0.c'\" unpacked with wrong size!
  963. fi
  964. # end of 'gets0.c'
  965. fi
  966. if test -f 'getsFF.c' -a "${1}" != "-c" ; then 
  967.   echo shar: Will not clobber existing file \"'getsFF.c'\"
  968. else
  969. echo shar: Extracting \"'getsFF.c'\" \(418 characters\)
  970. sed "s/^X//" >'getsFF.c' <<'END_OF_FILE'
  971. X/* Copyright (c) 1986, Greg McGary */
  972. Xstatic char sccsid[] = "@(#)getsFF.c    1.1 86/10/09";
  973. X
  974. X#include    <stdio.h>
  975. X
  976. Xint getsFF();
  977. Xvoid skipFF();
  978. X
  979. Xint
  980. XgetsFF(buf0, inFILE)
  981. X    char        *buf0;
  982. X    register FILE    *inFILE;
  983. X{
  984. X    register char    *buf = buf0;
  985. X
  986. X    while (((*buf++ = getc(inFILE)) & 0xff) != 0xff)
  987. X        ;
  988. X    return (buf - buf0 - 1);
  989. X}
  990. X
  991. Xvoid
  992. XskipFF(inFILE)
  993. X    register FILE    *inFILE;
  994. X{
  995. X    while ((getc(inFILE) & 0xff) != 0xff)
  996. X        ;
  997. X    return;
  998. X}
  999. END_OF_FILE
  1000. if test 418 -ne `wc -c <'getsFF.c'`; then
  1001.     echo shar: \"'getsFF.c'\" unpacked with wrong size!
  1002. fi
  1003. # end of 'getsFF.c'
  1004. fi
  1005. if test -f 'gid.el' -a "${1}" != "-c" ; then 
  1006.   echo shar: Will not clobber existing file \"'gid.el'\"
  1007. else
  1008. echo shar: Extracting \"'gid.el'\" \(788 characters\)
  1009. sed "s/^X//" >'gid.el' <<'END_OF_FILE'
  1010. X;;; put this in your GnuEmacs startup file  '~/.emacs' .
  1011. X;;; or autoload it from some other file. -wsr
  1012. X
  1013. X(require 'symfunc)
  1014. X
  1015. X(defun gid (command)
  1016. X  "Run gid, with user-specified args, and collect output in a buffer.
  1017. XWhile gid runs asynchronously, you can use the \\[next-error] command
  1018. Xto find the text that gid hits refer to."
  1019. X  (interactive (list (read-input "Run gid (with args): "
  1020. X                 (symbol-around-point))))
  1021. X  (require 'compile)
  1022. X  (compile1
  1023. X     (concat "gid " command)
  1024. X     "No more gid hits" "gid"
  1025. X  )
  1026. X)
  1027. X
  1028. X(defun aid (command)
  1029. X  "Run aid, with user-specified args, and collect output in a buffer."
  1030. X  (interactive (list (read-input "Run aid (with args): "
  1031. X                 (symbol-around-point))))
  1032. X  (require 'compile)
  1033. X  (compile1
  1034. X     (concat "aid -k " command)
  1035. X     "No aid hits" "aid"
  1036. X  )
  1037. X)
  1038. END_OF_FILE
  1039. if test 788 -ne `wc -c <'gid.el'`; then
  1040.     echo shar: \"'gid.el'\" unpacked with wrong size!
  1041. fi
  1042. # end of 'gid.el'
  1043. fi
  1044. if test -f 'hash.c' -a "${1}" != "-c" ; then 
  1045.   echo shar: Will not clobber existing file \"'hash.c'\"
  1046. else
  1047. echo shar: Extracting \"'hash.c'\" \(2237 characters\)
  1048. sed "s/^X//" >'hash.c' <<'END_OF_FILE'
  1049. X/* Copyright (c) 1986, Greg McGary */
  1050. Xstatic char sccsid[] = "@(#)hash.c    1.1 86/10/09";
  1051. X
  1052. Xchar *hashSearch();
  1053. Xint h1str();
  1054. Xint h2str();
  1055. X
  1056. X/*
  1057. X    Look for `key' in the hash table starting at address `base'.
  1058. X    `base' is a table containing `nel' elements of size `width'.
  1059. X    The hashing strategy we use is open addressing.  Apply the
  1060. X    primary hash function `h1' and the secondary hash function
  1061. X    `h2' when searching for `key' or an empty slot.  `compar'
  1062. X    is the comparison function that should be used to compare
  1063. X    the key with an element of the table.  It is called with two
  1064. X    arguments.  The first argument is the address of the key, and
  1065. X    the second argument is the address of the hash table element
  1066. X    in question.  `compar' should return 0 if the key matches the
  1067. X    element or the empty slot, and non-zero otherwise.
  1068. X
  1069. X    If a pointer to a long is provided for `probes' we will keep
  1070. X    a running total of open addressing hash probes.
  1071. X*/
  1072. Xchar *
  1073. XhashSearch(key, base, nel, width, h1, h2, compar, probes)
  1074. X    char        *key;        /* key to locate */
  1075. X    char        *base;        /* base of hash table */
  1076. X    register int    nel;        /* number of elements in table */
  1077. X    int        width;        /* width of each element */
  1078. X    unsigned int    (*h1)();    /* primary hash function */
  1079. X    unsigned int    (*h2)();    /* secondary hash function */
  1080. X    int        (*compar)();    /* key comparison function */
  1081. X    long        *probes;
  1082. X{
  1083. X    register unsigned int    hash1;
  1084. X    register unsigned int    hash2;
  1085. X    register char    *slot;
  1086. X
  1087. X    hash1 = (*h1)(key) % nel;
  1088. X    slot = &base[hash1 * width];
  1089. X
  1090. X    if (probes)
  1091. X        (*probes)++;
  1092. X    if ((*compar)(key, slot) == 0)
  1093. X        return slot;
  1094. X
  1095. X    hash2 = (*h2)(key);
  1096. X    for (;;) {
  1097. X        hash1 = (hash1 + hash2) % nel;
  1098. X        slot = &base[hash1 * width];
  1099. X
  1100. X        if (probes)
  1101. X            (*probes)++;
  1102. X        if ((*compar)(key, slot) == 0)
  1103. X            return slot;
  1104. X    }
  1105. X}
  1106. X
  1107. X#define    ABS(n)        ((n) < 0 ? -(n) : (n))
  1108. X
  1109. X/*
  1110. X    A Primary hash function for string keys.
  1111. X*/
  1112. Xint
  1113. Xh1str(key)
  1114. X    register char    *key;
  1115. X{
  1116. X    register int    sum;
  1117. X    register int    s;
  1118. X
  1119. X    for (sum = s = 0; *key; s++)
  1120. X        sum += ((*key++) << s);
  1121. X
  1122. X    return ABS(sum);
  1123. X}
  1124. X
  1125. X/*
  1126. X    A Secondary hash function for string keys.
  1127. X*/
  1128. Xint
  1129. Xh2str(key)
  1130. X    register char    *key;
  1131. X{
  1132. X    register int    sum;
  1133. X    register int    s;
  1134. X    char        *keysav;
  1135. X
  1136. X    keysav = key;
  1137. X    key = &key[strlen(key)];
  1138. X
  1139. X    for (sum = s = 0; key > keysav; s++)
  1140. X        sum += ((*--key) << s);
  1141. X
  1142. X    return ABS(sum) | 1;
  1143. X}
  1144. END_OF_FILE
  1145. if test 2237 -ne `wc -c <'hash.c'`; then
  1146.     echo shar: \"'hash.c'\" unpacked with wrong size!
  1147. fi
  1148. # end of 'hash.c'
  1149. fi
  1150. if test -f 'id.h' -a "${1}" != "-c" ; then 
  1151.   echo shar: Will not clobber existing file \"'id.h'\"
  1152. else
  1153. echo shar: Extracting \"'id.h'\" \(1716 characters\)
  1154. sed "s/^X//" >'id.h' <<'END_OF_FILE'
  1155. X/* Copyright (c) 1986, Greg McGary */
  1156. X/* @(#)id.h    1.1 86/10/09 */
  1157. X
  1158. X#define    IDFILE    "ID"
  1159. X
  1160. Xstruct idhead {
  1161. X    char    idh_magic[2];    /* magic number */
  1162. X#define    IDH_MAGIC "\311\304"    /* magic-number ("ID" with hi bits) */
  1163. X    short    idh_vers;    /* id-file version number */
  1164. X#define    IDH_VERS    2    /* current version */
  1165. X    int    idh_argc;    /* # of args for mkid update */
  1166. X    int    idh_pthc;    /* # of paths for mkid update */
  1167. X    int    idh_namc;    /* # of identifiers */
  1168. X    int    idh_vecc;    /* # of bytes in a path vector entry */
  1169. X    int    idh_bsiz;    /* # of bytes in entry (bufsiz for lid) */
  1170. X    long    idh_argo;    /* file offset of args for mkid update */
  1171. X    long    idh_namo;    /* file offset of identifier names */
  1172. X    long    idh_endo;    /* file offset of EOF */
  1173. X};
  1174. X
  1175. Xstruct idarg {
  1176. X    struct idarg    *ida_next;
  1177. X    char    *ida_arg;
  1178. X    int    ida_index;
  1179. X    char    ida_flags;
  1180. X#define    IDA_ADJUST    0x01
  1181. X#define    IDA_SCAN    0x02
  1182. X#define    IDA_PATH    0x04
  1183. X#define    IDA_ARG        0x08
  1184. X#define    IDA_BLANK    0x10
  1185. X};
  1186. X
  1187. Xstruct idname {
  1188. X    char    *idn_name;
  1189. X    char    *idn_bitv;
  1190. X    char    idn_flags;
  1191. X#define    IDN_SOLO    0x01    /* occurs only once */
  1192. X#define    IDN_NUMBER    0x02    /* is a number */
  1193. X#define    IDN_NAME    0x04    /* is a name */
  1194. X#define    IDN_STRING    0x08    /* is a string */
  1195. X#define    IDN_LITERAL    0x10    /* occurs as a literal (not string) */
  1196. X#define    IDN_NOISE    0x20    /* occurs very frequently */
  1197. X};
  1198. X
  1199. X/*
  1200. X    Extract the various logical fields of a name:
  1201. X
  1202. X    NAME: null-terminated ascii string
  1203. X    TAG:  index of name within a sorted array of all names
  1204. X    SOLO: boolean indicating that this name occurs exactly once
  1205. X*/
  1206. X#define    ID_PATHS(b) ((b)+strlen(b)+1)
  1207. X#define    ID_FLAGS(b) (*(b))
  1208. X#define    ID_STRING(b) ((b)+1)
  1209. X
  1210. X#define    NEW(type)    ((type *)calloc(1, sizeof(type)))
  1211. X
  1212. X#define    GETARG(argc, argv)    ((argc)--, *(argv)++)
  1213. X#define    UNGETARG(argc, argv)    ((argc)++, *--(argv))
  1214. END_OF_FILE
  1215. if test 1716 -ne `wc -c <'id.h'`; then
  1216.     echo shar: \"'id.h'\" unpacked with wrong size!
  1217. fi
  1218. # end of 'id.h'
  1219. fi
  1220. if test -f 'idx.c' -a "${1}" != "-c" ; then 
  1221.   echo shar: Will not clobber existing file \"'idx.c'\"
  1222. else
  1223. echo shar: Extracting \"'idx.c'\" \(1437 characters\)
  1224. sed "s/^X//" >'idx.c' <<'END_OF_FILE'
  1225. Xstatic char copyright[] = "@(#)Copyright (c) 1986, Greg McGary";
  1226. Xstatic char sccsid[] = "@(#)idx.c    1.2 86/10/17";
  1227. X
  1228. X#include    <stdio.h>
  1229. X#include    <string.h>
  1230. X#include    <id.h>
  1231. X#include    <extern.h>
  1232. X
  1233. Xvoid idxtract();
  1234. X
  1235. Xchar    *MyName;
  1236. Xstatic void
  1237. Xusage()
  1238. X{
  1239. X    fprintf(stderr, "Usage: %s [-u] [+/-a<ccc>] [-c<ccc>] files\n", MyName);
  1240. X    exit(1);
  1241. X}
  1242. Xmain(argc, argv)
  1243. X    int        argc;
  1244. X    char        **argv;
  1245. X{
  1246. X    char        *arg;
  1247. X    int        op;
  1248. X    char        *sccsDir = NULL;
  1249. X    char        *rcsDir = NULL;
  1250. X
  1251. X    MyName = basename(GETARG(argc, argv));
  1252. X    while (argc) {
  1253. X        arg = GETARG(argc, argv);
  1254. X        switch (op = *arg++)
  1255. X        {
  1256. X        case '-':
  1257. X        case '+':
  1258. X            break;
  1259. X        default:
  1260. X            UNGETARG(argc, argv);
  1261. X            goto argsdone;
  1262. X        }
  1263. X        switch (*arg++)
  1264. X        {
  1265. X        case 's': sccsDir = arg; break;
  1266. X        case 'r': rcsDir = arg; break;
  1267. X        case 'S': setScanArgs(op, arg); break;
  1268. X        default: usage();
  1269. X        }
  1270. X    }
  1271. Xargsdone:
  1272. X
  1273. X    if (argc == 0)
  1274. X        usage();
  1275. X    while (argc)
  1276. X        idxtract(GETARG(argc, argv), sccsDir, rcsDir);
  1277. X    exit(0);
  1278. X}
  1279. X
  1280. Xvoid
  1281. Xidxtract(path, sccsDir, rcsDir)
  1282. X    char        *path;
  1283. X    char        *sccsDir;
  1284. X    char        *rcsDir;
  1285. X{
  1286. X    register char    *key;
  1287. X    register char    *(*getId)();
  1288. X    register FILE    *srcFILE;
  1289. X    char        *(*getScanner())();
  1290. X    int        flags;
  1291. X    char        *suffix;
  1292. X    char        *filter;
  1293. X
  1294. X    if ((getId = getScanner(getLanguage(suffix=strrchr(path, '.')))) == NULL)
  1295. X        return;
  1296. X    if ((srcFILE = openSrcFILE(path, sccsDir, rcsDir, filter=getFilter(suffix))) == NULL)
  1297. X        return;
  1298. X
  1299. X    while ((key = (*getId)(srcFILE, &flags)) != NULL)
  1300. X        puts(key);
  1301. X
  1302. X    closeSrcFILE(srcFILE, filter);
  1303. X}
  1304. END_OF_FILE
  1305. if test 1437 -ne `wc -c <'idx.c'`; then
  1306.     echo shar: \"'idx.c'\" unpacked with wrong size!
  1307. fi
  1308. # end of 'idx.c'
  1309. fi
  1310. if test -f 'init.c' -a "${1}" != "-c" ; then 
  1311.   echo shar: Will not clobber existing file \"'init.c'\"
  1312. else
  1313. echo shar: Extracting \"'init.c'\" \(1442 characters\)
  1314. sed "s/^X//" >'init.c' <<'END_OF_FILE'
  1315. X/* Copyright (c) 1986, Greg McGary */
  1316. Xstatic char sccsid[] = "@(#)init.c    1.1 86/10/09";
  1317. X
  1318. X#include    <id.h>
  1319. X#include    <string.h>
  1320. X#include    <stdio.h>
  1321. X#include    <extern.h>
  1322. X
  1323. X/* initID opens idFile, reads the header into idhp (and verifies the magic
  1324. X * number), then builds the idArgs list holding the names of all the
  1325. X * files recorded in the database.
  1326. X */
  1327. XFILE *
  1328. XinitID(idFile, idhp, idArgs)
  1329. X    char        *idFile;
  1330. X    struct idhead    *idhp;
  1331. X    struct idarg    **idArgs;
  1332. X{
  1333. X    FILE        *idFILE;
  1334. X    register int    i;
  1335. X    register char    *strings;
  1336. X    register struct idarg    *idArg;
  1337. X
  1338. X    if ((idFILE = fopen(idFile, "r")) == NULL)
  1339. X        return NULL;
  1340. X
  1341. X    fseek(idFILE, 0L, 0);
  1342. X    fread(idhp, sizeof(struct idhead), 1, idFILE);
  1343. X    if (!strnequ(idhp->idh_magic, IDH_MAGIC, sizeof(idhp->idh_magic))) {
  1344. X        fprintf(stderr, "%s: Not an id file: `%s'\n", MyName, idFile);
  1345. X        exit(1);
  1346. X    }
  1347. X    if (idhp->idh_vers != IDH_VERS) {
  1348. X        fprintf(stderr, "%s: ID version mismatch (want: %d, got: %d)\n", MyName, IDH_VERS, idhp->idh_vers);
  1349. X        exit(1);
  1350. X    }
  1351. X
  1352. X    fseek(idFILE, idhp->idh_argo, 0);
  1353. X    strings = malloc(i = idhp->idh_namo - idhp->idh_argo);
  1354. X    fread(strings, i, 1, idFILE);
  1355. X    idArg = *idArgs = (struct idarg *)calloc(idhp->idh_pthc, sizeof(struct idarg));
  1356. X    for (i = 0; i < idhp->idh_argc; i++) {
  1357. X        if (*strings == '+' || *strings == '-')
  1358. X            goto skip;
  1359. X        idArg->ida_flags = (*strings) ? 0 : IDA_BLANK;
  1360. X        idArg->ida_arg = strings;
  1361. X        idArg->ida_next = idArg + 1;
  1362. X        idArg++;
  1363. X    skip:
  1364. X        while (*strings++)
  1365. X            ;
  1366. X    }
  1367. X    return idFILE;
  1368. X}
  1369. END_OF_FILE
  1370. if test 1442 -ne `wc -c <'init.c'`; then
  1371.     echo shar: \"'init.c'\" unpacked with wrong size!
  1372. fi
  1373. # end of 'init.c'
  1374. fi
  1375. if test -f 'kshgetwd.c' -a "${1}" != "-c" ; then 
  1376.   echo shar: Will not clobber existing file \"'kshgetwd.c'\"
  1377. else
  1378. echo shar: Extracting \"'kshgetwd.c'\" \(1781 characters\)
  1379. sed "s/^X//" >'kshgetwd.c' <<'END_OF_FILE'
  1380. X#include <string.h>
  1381. X#include <sys/param.h>
  1382. X#include <sys/stat.h>
  1383. X
  1384. Xextern char * getenv();
  1385. Xextern void cannoname();
  1386. Xextern char * unsymlink();
  1387. Xextern char * getwd();
  1388. X
  1389. X/* kshgetwd is a routine that acts just like getwd, but is optimized
  1390. X * for ksh users, taking advantage of the fact that ksh maintains
  1391. X * an environment variable named PWD holding path name of the
  1392. X * current working directory.
  1393. X *
  1394. X * The primary motivation for this is not really that it is algorithmically
  1395. X * simpler, but that it is much less likely to bother NFS if we can just
  1396. X * guess the name of the current working directory using the hint that
  1397. X * ksh maintains. Anything that avoids NFS gettar failed messages is
  1398. X * worth doing.
  1399. X */
  1400. Xchar *
  1401. Xkshgetwd(pathname)
  1402. X   char *   pathname;
  1403. X{
  1404. X   struct stat kshstat, dotstat ;
  1405. X   char        kshname[MAXPATHLEN] ;
  1406. X   char *      kshp ;
  1407. X
  1408. X   kshp = getenv("PWD") ;
  1409. X   if (kshp) {
  1410. X      /* OK, there was a PWD environment variable */
  1411. X      strcpy(kshname, kshp) ;
  1412. X      if (unsymlink(kshname)) {
  1413. X         /* And we could resolve the symbolic links through it */
  1414. X         if (kshname[0] == '/') {
  1415. X            /* And the name we have is an absolute path name */
  1416. X            if (stat(kshname, &kshstat) == 0) {
  1417. X               /* And we can stat the name */
  1418. X               if (stat(".", &dotstat) == 0) {
  1419. X                  /* And we can stat "." */
  1420. X                  if ((kshstat.st_dev == dotstat.st_dev) &&
  1421. X                      (kshstat.st_ino == dotstat.st_ino)) {
  1422. X                     /* By golly, that name is the same file as "." ! */
  1423. X                     return(strcpy(pathname, kshname)) ;
  1424. X                  }
  1425. X               }
  1426. X            }
  1427. X         }
  1428. X      }
  1429. X   }
  1430. X   /* Oh well, something did not work out right, do it the hard way */
  1431. X   return(getwd(pathname)) ;
  1432. X}
  1433. END_OF_FILE
  1434. if test 1781 -ne `wc -c <'kshgetwd.c'`; then
  1435.     echo shar: \"'kshgetwd.c'\" unpacked with wrong size!
  1436. fi
  1437. # end of 'kshgetwd.c'
  1438. fi
  1439. if test -f 'numtst.c' -a "${1}" != "-c" ; then 
  1440.   echo shar: Will not clobber existing file \"'numtst.c'\"
  1441. else
  1442. echo shar: Extracting \"'numtst.c'\" \(60 characters\)
  1443. sed "s/^X//" >'numtst.c' <<'END_OF_FILE'
  1444. X000004
  1445. X00010
  1446. X012
  1447. X020
  1448. X04
  1449. X0x00004
  1450. X0x00010
  1451. X0x00a
  1452. X0XA
  1453. X10
  1454. X16
  1455. X4
  1456. X8
  1457. END_OF_FILE
  1458. if test 60 -ne `wc -c <'numtst.c'`; then
  1459.     echo shar: \"'numtst.c'\" unpacked with wrong size!
  1460. fi
  1461. # end of 'numtst.c'
  1462. fi
  1463. if test -f 'opensrc.c' -a "${1}" != "-c" ; then 
  1464.   echo shar: Will not clobber existing file \"'opensrc.c'\"
  1465. else
  1466. echo shar: Extracting \"'opensrc.c'\" \(2529 characters\)
  1467. sed "s/^X//" >'opensrc.c' <<'END_OF_FILE'
  1468. X/* Copyright (c) 1986, Greg McGary */
  1469. Xstatic char sccsid[] = "@(#)opensrc.c    1.1 86/10/09";
  1470. X
  1471. X#include    <stdio.h>
  1472. X#include    <string.h>
  1473. X#include    <sys/types.h>
  1474. X#include    <sys/stat.h>
  1475. X
  1476. Xchar *findSrcFILE();
  1477. Xchar *getSCCS();
  1478. Xchar *coRCS();
  1479. X
  1480. XFILE *
  1481. XopenSrcFILE(path, sccsDir, rcsDir, filter)
  1482. X    char        *path;
  1483. X    char        *sccsDir;
  1484. X    char        *rcsDir;
  1485. X    char        *filter;
  1486. X{
  1487. X    char        *command = NULL;
  1488. X    char        *what = NULL;
  1489. X    char        *get = "get SCCS file";
  1490. X    char        *checkout = "checkout RCS file";
  1491. X    char        *dirName;
  1492. X    char        *baseName;
  1493. X    struct stat    statb;
  1494. X    char        popcom[1024];
  1495. X    FILE        *srcFILE;
  1496. X
  1497. X    if (stat(path, &statb) != 0) {
  1498. X        if ((baseName = strrchr(path, '/')) == NULL) {
  1499. X            dirName = ".";
  1500. X            baseName = path;
  1501. X        } else {
  1502. X            dirName = path;
  1503. X            *baseName++ = '\0';
  1504. X        }
  1505. X
  1506. X        if (rcsDir && (command = coRCS(dirName, baseName, rcsDir)))
  1507. X            what = checkout;
  1508. X        else if (sccsDir && (command = getSCCS(dirName, baseName, sccsDir)))
  1509. X            what = get;
  1510. X        else if ((command = coRCS(dirName, baseName, "RCS"))
  1511. X             ||  (command = coRCS(dirName, baseName, ".")))
  1512. X            what = checkout;
  1513. X        else if ((command = getSCCS(dirName, baseName, "SCCS"))
  1514. X             ||  (command = getSCCS(dirName, baseName, "sccs"))
  1515. X             ||  (command = getSCCS(dirName, baseName, ".")))
  1516. X            what = get;
  1517. X
  1518. X        if (dirName == path)
  1519. X            *--baseName = '/';
  1520. X
  1521. X        if (!command) {
  1522. X            filerr("open", path);
  1523. X            return NULL;
  1524. X        }
  1525. X
  1526. X        system(command);
  1527. X        fprintf(stderr, "%s\n", command);
  1528. X    }
  1529. X    if (stat(path, &statb) != 0) {
  1530. X        filerr("open", path);
  1531. X        return NULL;
  1532. X    }
  1533. X    if (filter != NULL) {
  1534. X        sprintf(popcom,filter,path);
  1535. X        srcFILE = popen(popcom, "r");
  1536. X    } else {
  1537. X        srcFILE = fopen(path, "r");
  1538. X    }
  1539. X    if (srcFILE == NULL) {
  1540. X        filerr("open", path);
  1541. X    }
  1542. X    return srcFILE;
  1543. X}
  1544. X
  1545. Xvoid
  1546. XcloseSrcFILE(fp, filter)
  1547. X    FILE        *fp;
  1548. X    char        *filter;
  1549. X{
  1550. X    if (filter != NULL) {
  1551. X        pclose(fp);
  1552. X    } else {
  1553. X        fclose(fp);
  1554. X    }
  1555. X}
  1556. X
  1557. Xchar *
  1558. XgetSCCS(dir, base, sccsDir)
  1559. X    char        *dir;
  1560. X    char        *base;
  1561. X    char        *sccsDir;
  1562. X{
  1563. X    static char    cmdBuf[BUFSIZ];
  1564. X    char        fileBuf[BUFSIZ];
  1565. X    struct stat    statBuf;
  1566. X
  1567. X    if (!*sccsDir)
  1568. X        sccsDir = ".";
  1569. X
  1570. X    sprintf(fileBuf, "%s/%s/s.%s", dir, sccsDir, base);
  1571. X    if (stat(fileBuf, &statBuf) < 0)
  1572. X        return NULL;
  1573. X    sprintf(cmdBuf, "cd %s; get -s %s/s.%s", dir, sccsDir, base);
  1574. X
  1575. X    return cmdBuf;
  1576. X}
  1577. X
  1578. Xchar *
  1579. XcoRCS(dir, base, rcsDir)
  1580. X    char        *dir;
  1581. X    char        *base;
  1582. X    char        *rcsDir;
  1583. X{
  1584. X    static char    cmdBuf[BUFSIZ];
  1585. X    char        fileBuf[BUFSIZ];
  1586. X    struct stat    statBuf;
  1587. X
  1588. X    if (!*rcsDir)
  1589. X        rcsDir = ".";
  1590. X
  1591. X    sprintf(fileBuf, "%s/%s/%s,v", dir, rcsDir, base);
  1592. X    if (stat(fileBuf, &statBuf) < 0)
  1593. X        return NULL;
  1594. X    sprintf(cmdBuf, "cd %s; co -q %s/%s,v", dir, rcsDir, base);
  1595. X
  1596. X    return cmdBuf;
  1597. X}
  1598. END_OF_FILE
  1599. if test 2529 -ne `wc -c <'opensrc.c'`; then
  1600.     echo shar: \"'opensrc.c'\" unpacked with wrong size!
  1601. fi
  1602. # end of 'opensrc.c'
  1603. fi
  1604. if test -f 'patchlevel.h' -a "${1}" != "-c" ; then 
  1605.   echo shar: Will not clobber existing file \"'patchlevel.h'\"
  1606. else
  1607. echo shar: Extracting \"'patchlevel.h'\" \(21 characters\)
  1608. sed "s/^X//" >'patchlevel.h' <<'END_OF_FILE'
  1609. X#define PATCHLEVEL 2
  1610. END_OF_FILE
  1611. if test 21 -ne `wc -c <'patchlevel.h'`; then
  1612.     echo shar: \"'patchlevel.h'\" unpacked with wrong size!
  1613. fi
  1614. # end of 'patchlevel.h'
  1615. fi
  1616. if test -f 'radix.h' -a "${1}" != "-c" ; then 
  1617.   echo shar: Will not clobber existing file \"'radix.h'\"
  1618. else
  1619. echo shar: Extracting \"'radix.h'\" \(225 characters\)
  1620. sed "s/^X//" >'radix.h' <<'END_OF_FILE'
  1621. X/* Copyright (c) 1986, Greg McGary */
  1622. X/* @(#)radix.h    1.1 86/10/09 */
  1623. X
  1624. X#define    RADIX_DEC    (1 << (10 - 1))
  1625. X#define    RADIX_OCT    (1 << (010 - 1))
  1626. X#define    RADIX_HEX    (1 << (0x10 - 1))
  1627. X#define    RADIX_ALL    (RADIX_DEC|RADIX_OCT|RADIX_HEX)
  1628. END_OF_FILE
  1629. if test 225 -ne `wc -c <'radix.h'`; then
  1630.     echo shar: \"'radix.h'\" unpacked with wrong size!
  1631. fi
  1632. # end of 'radix.h'
  1633. fi
  1634. if test -f 'stoi.c' -a "${1}" != "-c" ; then 
  1635.   echo shar: Will not clobber existing file \"'stoi.c'\"
  1636. else
  1637. echo shar: Extracting \"'stoi.c'\" \(1883 characters\)
  1638. sed "s/^X//" >'stoi.c' <<'END_OF_FILE'
  1639. X/* Copyright (c) 1986, Greg McGary */
  1640. Xstatic char sccsid[] = "@(#)stoi.c    1.1 86/10/09";
  1641. X
  1642. X#include    <radix.h>
  1643. X#include    <ctype.h>
  1644. X
  1645. Xint dtoi();
  1646. Xint otoi();
  1647. Xint radix();
  1648. Xint stoi();
  1649. Xint xtoi();
  1650. X
  1651. X/*
  1652. X    Use the C lexical rules to determine an ascii number's radix.
  1653. X    The radix is returned as a bit map, so that more than one radix
  1654. X    may apply.  In particular, it is impossible to determine the
  1655. X    radix of 0, so return all possibilities.
  1656. X*/
  1657. Xint
  1658. Xradix(name)
  1659. X    register char    *name;
  1660. X{
  1661. X    if (!isdigit(*name))
  1662. X        return 0;
  1663. X    if (*name != '0')
  1664. X        return RADIX_DEC;
  1665. X    name++;
  1666. X    if (*name == 'x' || *name == 'X')
  1667. X        return RADIX_HEX;
  1668. X    while (*name && *name == '0')
  1669. X        name++;
  1670. X    return (RADIX_OCT | ((*name)?0:RADIX_DEC));
  1671. X}
  1672. X
  1673. X/*
  1674. X    Convert an ascii string number to an integer.
  1675. X    Determine the radix before converting.
  1676. X*/
  1677. Xint
  1678. Xstoi(name)
  1679. X    char        *name;
  1680. X{
  1681. X    switch (radix(name))
  1682. X    {
  1683. X    case RADIX_DEC:    return(dtoi(name));
  1684. X    case RADIX_OCT:    return(otoi(&name[1]));
  1685. X    case RADIX_HEX:    return(xtoi(&name[2]));
  1686. X    case RADIX_DEC|RADIX_OCT: return(0);
  1687. X    default:    return(-1);
  1688. X    }
  1689. X}
  1690. X
  1691. X/*
  1692. X    Convert an ascii octal number to an integer.
  1693. X*/
  1694. Xint
  1695. Xotoi(name)
  1696. X    char        *name;
  1697. X{
  1698. X    register int    n = 0;
  1699. X
  1700. X    while (*name >= '0' && *name <= '7') {
  1701. X        n *= 010;
  1702. X        n += *name++ - '0';
  1703. X    }
  1704. X    if (*name == 'l' || *name == 'L')
  1705. X        name++;
  1706. X    return (*name ? -1 : n);
  1707. X}
  1708. X
  1709. X/*
  1710. X    Convert an ascii decimal number to an integer.
  1711. X*/
  1712. Xint
  1713. Xdtoi(name)
  1714. X    char        *name;
  1715. X{
  1716. X    register int    n = 0;
  1717. X
  1718. X    while (isdigit(*name)) {
  1719. X        n *= 10;
  1720. X        n += *name++ - '0';
  1721. X    }
  1722. X    if (*name == 'l' || *name == 'L')
  1723. X        name++;
  1724. X    return (*name ? -1 : n);
  1725. X}
  1726. X
  1727. X/*
  1728. X    Convert an ascii hex number to an integer.
  1729. X*/
  1730. Xint
  1731. Xxtoi(name)
  1732. X    char        *name;
  1733. X{
  1734. X    register int    n = 0;
  1735. X
  1736. X    while (isxdigit(*name)) {
  1737. X        n *= 0x10;
  1738. X        if (isdigit(*name))
  1739. X            n += *name++ - '0';
  1740. X        else if (islower(*name))
  1741. X            n += 0xa + *name++ - 'a';
  1742. X        else
  1743. X            n += 0xA + *name++ - 'A';
  1744. X    }
  1745. X    if (*name == 'l' || *name == 'L')
  1746. X        name++;
  1747. X    return (*name ? -1 : n);
  1748. X}
  1749. END_OF_FILE
  1750. if test 1883 -ne `wc -c <'stoi.c'`; then
  1751.     echo shar: \"'stoi.c'\" unpacked with wrong size!
  1752. fi
  1753. # end of 'stoi.c'
  1754. fi
  1755. if test -f 'string.h' -a "${1}" != "-c" ; then 
  1756.   echo shar: Will not clobber existing file \"'string.h'\"
  1757. else
  1758. echo shar: Extracting \"'string.h'\" \(525 characters\)
  1759. sed "s/^X//" >'string.h' <<'END_OF_FILE'
  1760. X/* Copyright (c) 1986, Greg McGary */
  1761. X/* @(#)string.h    1.1 86/10/09 */
  1762. X
  1763. X#ifdef RINDEX
  1764. X#define    strchr    index
  1765. X#define    strrchr    rindex
  1766. X#endif
  1767. X
  1768. Xextern char
  1769. X    *strcpy(),
  1770. X    *strncpy(),
  1771. X    *strcat(),
  1772. X    *strncat(),
  1773. X    *strchr(),
  1774. X    *strrchr(),
  1775. X    *strpbrk(),
  1776. X    *strtok();
  1777. X
  1778. Xextern long
  1779. X    strtol();
  1780. X
  1781. Xextern char    *calloc();
  1782. X
  1783. X#define    strequ(s1, s2)        (strcmp((s1), (s2)) == 0)
  1784. X#define    strnequ(s1, s2, n)    (strncmp((s1), (s2), (n)) == 0)
  1785. X#define    strsav(s)        (strcpy(calloc(1, strlen(s)+1), (s)))
  1786. X#define    strnsav(s, n)        (strncpy(calloc(1, (n)+1), (s), (n)))
  1787. END_OF_FILE
  1788. if test 525 -ne `wc -c <'string.h'`; then
  1789.     echo shar: \"'string.h'\" unpacked with wrong size!
  1790. fi
  1791. # end of 'string.h'
  1792. fi
  1793. if test -f 'tty.c' -a "${1}" != "-c" ; then 
  1794.   echo shar: Will not clobber existing file \"'tty.c'\"
  1795. else
  1796. echo shar: Extracting \"'tty.c'\" \(1114 characters\)
  1797. sed "s/^X//" >'tty.c' <<'END_OF_FILE'
  1798. X#ifdef TERMIO
  1799. X#include    <sys/termio.h>
  1800. X
  1801. Xstruct termio linemode, charmode, savemode;
  1802. X
  1803. Xsavetty()
  1804. X{
  1805. X    ioctl(0, TCGETA, &savemode);
  1806. X    charmode = linemode = savemode;
  1807. X
  1808. X    charmode.c_lflag &= ~(ECHO|ICANON|ISIG);
  1809. X    charmode.c_cc[VMIN] = 1;
  1810. X    charmode.c_cc[VTIME] = 0;
  1811. X
  1812. X    linemode.c_lflag |= (ECHO|ICANON|ISIG);
  1813. X    linemode.c_cc[VEOF] = 'd'&037;
  1814. X    linemode.c_cc[VEOL] = 0377;
  1815. X}
  1816. X
  1817. Xrestoretty()
  1818. X{
  1819. X    ioctl(0, TCSETA, &savemode);
  1820. X}
  1821. X
  1822. Xlinetty()
  1823. X{
  1824. X    ioctl(0, TCSETA, &linemode);
  1825. X}
  1826. X
  1827. Xchartty()
  1828. X{
  1829. X    ioctl(0, TCSETA, &charmode);
  1830. X}
  1831. X
  1832. X#else
  1833. X#include    <sgtty.h>
  1834. X
  1835. Xstruct sgttyb linemode, charmode, savemode;
  1836. X
  1837. Xsavetty()
  1838. X{
  1839. X#ifdef TIOCGETP
  1840. X    ioctl(0, TIOCGETP, &savemode);
  1841. X#else
  1842. X    gtty(0, &savemode);
  1843. X#endif
  1844. X    charmode = linemode = savemode;
  1845. X
  1846. X    charmode.sg_flags &= ~ECHO;
  1847. X    charmode.sg_flags |= RAW;
  1848. X
  1849. X    linemode.sg_flags |= ECHO;
  1850. X    linemode.sg_flags &= ~RAW;
  1851. X}
  1852. X
  1853. Xrestoretty()
  1854. X{
  1855. X#ifdef TIOCSETP
  1856. X    ioctl(0, TIOCSETP, &savemode);
  1857. X#else
  1858. X    stty(0, &savemode);
  1859. X#endif
  1860. X}
  1861. X
  1862. Xlinetty()
  1863. X{
  1864. X#ifdef TIOCSETP
  1865. X    ioctl(0, TIOCSETP, &linemode);
  1866. X#else
  1867. X    stty(0, &savemode);
  1868. X#endif
  1869. X}
  1870. X
  1871. Xchartty()
  1872. X{
  1873. X#ifdef TIOCSETP
  1874. X    ioctl(0, TIOCSETP, &charmode);
  1875. X#else
  1876. X    stty(0, &savemode);
  1877. X#endif
  1878. X}
  1879. X#endif
  1880. END_OF_FILE
  1881. if test 1114 -ne `wc -c <'tty.c'`; then
  1882.     echo shar: \"'tty.c'\" unpacked with wrong size!
  1883. fi
  1884. # end of 'tty.c'
  1885. fi
  1886. if test -f 'uerror.c' -a "${1}" != "-c" ; then 
  1887.   echo shar: Will not clobber existing file \"'uerror.c'\"
  1888. else
  1889. echo shar: Extracting \"'uerror.c'\" \(586 characters\)
  1890. sed "s/^X//" >'uerror.c' <<'END_OF_FILE'
  1891. X/* Copyright (c) 1986, Greg McGary */
  1892. Xstatic char sccsid[] = "@(#)uerror.c    1.1 86/10/09";
  1893. X
  1894. X#include    <stdio.h>
  1895. X
  1896. Xchar *uerror();
  1897. Xvoid filerr();
  1898. X
  1899. Xextern int    errno;
  1900. Xextern int    sys_nerr;
  1901. Xextern char    *sys_errlist[];
  1902. Xextern char    *MyName;
  1903. X
  1904. Xchar    cannot[] = "%s: Cannot %s `%s' (%s)\n";
  1905. X
  1906. Xchar *
  1907. Xuerror()
  1908. X{
  1909. X    static char    errbuf[10];
  1910. X
  1911. X    if (errno == 0 || errno >= sys_nerr) {
  1912. X        sprintf(errbuf, "error %d", errno);
  1913. X        return(errbuf);
  1914. X    }
  1915. X    return(sys_errlist[errno]);
  1916. X}
  1917. X
  1918. Xvoid
  1919. Xfilerr(syscall, fileName)
  1920. X    char        *syscall;
  1921. X    char        *fileName;
  1922. X{
  1923. X    fprintf(stderr, cannot, MyName, syscall, fileName, uerror());
  1924. X}
  1925. END_OF_FILE
  1926. if test 586 -ne `wc -c <'uerror.c'`; then
  1927.     echo shar: \"'uerror.c'\" unpacked with wrong size!
  1928. fi
  1929. # end of 'uerror.c'
  1930. fi
  1931. if test -f 'wmatch.c' -a "${1}" != "-c" ; then 
  1932.   echo shar: Will not clobber existing file \"'wmatch.c'\"
  1933. else
  1934. echo shar: Extracting \"'wmatch.c'\" \(830 characters\)
  1935. sed "s/^X//" >'wmatch.c' <<'END_OF_FILE'
  1936. X/* Copyright (c) 1986, Greg McGary */
  1937. Xstatic char sccsid[] = "@(#)wmatch.c    1.1 86/10/09";
  1938. X
  1939. X#include    <bool.h>
  1940. X#include    <ctype.h>
  1941. X
  1942. Xbool wordMatch();
  1943. X
  1944. X/*
  1945. X    Does `name' occur in `line' delimited by non-alphanumerics??
  1946. X*/
  1947. Xbool
  1948. XwordMatch(name0, line)
  1949. X    char        *name0;
  1950. X    register char    *line;
  1951. X{
  1952. X    register char    *name = name0;
  1953. X#define IS_ALNUM(c)    (isalnum(c) || (c) == '_')
  1954. X
  1955. X    for (;;) {
  1956. X        /* find an initial-character match */
  1957. X        while (*line != *name) {
  1958. X            if (*line == '\n')
  1959. X                return FALSE;
  1960. X            line++;
  1961. X        }
  1962. X        /* do we have a word delimiter on the left ?? */
  1963. X        if (IS_ALNUM(line[-1])) {
  1964. X            line++;
  1965. X            continue;
  1966. X        }
  1967. X        /* march down both strings as long as we match */
  1968. X        while (*++name == *++line)
  1969. X            ;
  1970. X        /* is this the end of `name', is there a word delimiter ?? */
  1971. X        if (*name == '\0' && !IS_ALNUM(*line))
  1972. X            return TRUE;
  1973. X        name = name0;
  1974. X    }
  1975. X}
  1976. END_OF_FILE
  1977. if test 830 -ne `wc -c <'wmatch.c'`; then
  1978.     echo shar: \"'wmatch.c'\" unpacked with wrong size!
  1979. fi
  1980. # end of 'wmatch.c'
  1981. fi
  1982. echo shar: End of archive 1 \(of 7\).
  1983. cp /dev/null ark1isdone
  1984. MISSING=""
  1985. for I in 1 2 3 4 5 6 7 ; do
  1986.     if test ! -f ark${I}isdone ; then
  1987.     MISSING="${MISSING} ${I}"
  1988.     fi
  1989. done
  1990. if test "${MISSING}" = "" ; then
  1991.     echo You have unpacked all 7 archives.
  1992.     rm -f ark[1-9]isdone
  1993. else
  1994.     echo You still need to unpack the following archives:
  1995.     echo "        " ${MISSING}
  1996. fi
  1997. ##  End of shell archive.
  1998. exit 0
  1999.  
  2000. exit 0 # Just in case...
  2001.